package com.qr.controller;

import com.qr.pojo.Buy;
import com.qr.service.BuyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
@Controller
    @RequestMapping("/buy")
    public class BuyController {
        //Controller调service层
        @Autowired
        private BuyService buyService;
        //查询全部，并且返回到一个展示页面
        @RequestMapping("/allBuy")
        public String list(Model model) {
            List<Buy> list = buyService.AllBuy();
            model.addAttribute("list", list);
            return "allBuy";
        }

    //跳转到添加页面
    @RequestMapping("/toAddBuy")
    public String toAddBuy(String username,Model mod) {
            Buy buy =new Buy();
            buy.setUsername(username);
        mod.addAttribute("getbuy",buy);
        return "addBuy";
    }

    @RequestMapping("/addBuy")
    public String addBuy(Buy buy) {
        System.out.println(buy);
        buyService.addBuy(buy);
        return "redirect:/buy/allBuy";
    }
}
